package com.design.pattern;

import java.util.ArrayList;
import java.util.List;

public class BuildePattern {
    public static void main(String[] args){
       MealBuilder mealBuilder = new MealBuilder();
       Meal nonVegMeal =  mealBuilder.prepareNonVegMeal();
       System.out.println("nonVegMeal-------------");
       nonVegMeal.showItems();
       System.out.println("totle cost: " + nonVegMeal.getCost());
       Meal vegMeal = mealBuilder.prepareVegMeal();
       System.out.println("vegMeal-------------");
       vegMeal.showItems();
       System.out.println("totle cost: " + vegMeal.getCost());
    }
}

interface Item{
    String name();
    Packing packing();
    float price();
}
abstract class Burger implements Item{
    @Override
    public Packing packing() {
        return new Wrapper();
    }

    @Override
    public abstract float price();
}

class VegBurger extends Burger{

    @Override
    public String name() {
        return "veg burger";
    }

    @Override
    public float price() {
        return 25.0F;
    }
}
class ChickenBurger extends Burger{

    @Override
    public String name() {
        return "chicken burger";
    }

    @Override
    public float price() {
        return 50.5F;
    }
}


abstract class ColdDrink implements Item{

    @Override
    public Packing packing() {
        return new Bottle();
    }

    @Override
    public abstract float price();
}
class Pepsi extends ColdDrink{

    @Override
    public String name() {
        return "pepsi";
    }

    @Override
    public float price() {
        return 5.0F;
    }
}
class Coke extends ColdDrink{
    @Override
    public String name() {
        return "coke";
    }

    @Override
    public float price() {
        return 10.0F;
    }
}

interface Packing{
    String pack();
}
class Wrapper implements Packing{
    @Override
    public String pack() {
        return "wrapper";
    }
}
class Bottle implements Packing{
    @Override
    public String pack() {
        return "bottle";
    }
}

class Meal{
    private List<Item> items = new ArrayList<>();

    public void addItem(Item item){
        items.add(item);
    }
    public float getCost(){
        float cost = 0.0f;
        for (Item item : items) {
            cost += item.price();
        }
        return cost;
    }

    public void showItems(){
        for (Item item : items) {
            System.out.print("Item : "+item.name());
            System.out.print(", Packing : "+item.packing().pack());
            System.out.println(", Price : "+item.price());
        }
    }
}

class MealBuilder{
    public Meal prepareVegMeal(){
        Meal meal = new Meal();
        meal.addItem(new VegBurger());
        meal.addItem( new Pepsi());
        return meal;
    }
    public Meal prepareNonVegMeal(){
        Meal meal = new Meal();
        meal.addItem(new ChickenBurger());
        meal.addItem(new Coke());
        return meal;
    }
}
